import { createRouter, createWebHistory } from "vue-router";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      redirect: "/Login",
    },
    {
      path: "/Login",
      component: () => import("../views/Login/index.vue"),
    },
    {
      name: "Admin",
      path: "/Admin",
      component: () => import("../views/Admin/index.vue"),
      meta: { requiresAuth: true },
    },
  ],
});
router.beforeEach((to, from, next) => {
  if (to.meta.requiresAuth && !sessionStorage.getItem("token")) {
    next("/Login");
  } else {
    next();
  }
});
export default router;
